window.onload=function(){
	dlzc();
	yzm();
}
var currentObj;             //保存被选中的对象
//鼠标点击登陆注册，内容切换显示隐藏
function dlzc(){
	var dlzc_a = document.getElementsByClassName("main-biaoti")[0].getElementsByTagName("a");
	var dlzc_denglu=document.getElementsByClassName("main-denglu")[0];
	var dlzc_zhuce=document.getElementsByClassName("main-zhuce")[0];
	for (var i = 0; i < dlzc_a.length; i++) {
		console.log(dlzc_a[i])
		dlzc_a[i].index=i;
		dlzc_a[i].onclick=function(){
			var index = this.index;
			if(currentObj) {
				currentObj.style.color="#ccc";
				currentObj.style.borderBottom="1px solid #ccc";
			}
			this.style.color = "#009FBD";
			this.style.borderBottom="1px solid #009fbd";
			currentObj = this;
			
			if (index==0){
				dlzc_denglu.style.display="block";
				dlzc_zhuce.style.display="none";
			} else{
				dlzc_zhuce.style.display="block";
				dlzc_denglu.style.display="none";
			}
			
		}
		
	}
	console.log(dlzc_a);
}


//随机生成验证码
	
function yzm(){
	var codeStr = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM12345567890"
	var odiv = document.getElementsByClassName("yzm")[0];
	function getRandom(n,m){
		n=Number(n);
		m=Number(m);
		if(isNaN(n)||isNaN(m)){
			return Math.random();
		}
		if (n>m) {
			var temp = n;
			n=m;
			m=temp;	
		}
		return Math.round(Math.random()*(m-n)+n);
	}
	
	function getCode(){
		var str=""
		for (var i = 0; i < 4; i++) {
			var ran = getRandom(0,61);
			str+= codeStr.charAt(ran);
		}
		odiv.innerHTML=str;
		
	}
	getCode();	
}


/*----------------------------表单验证-------------------------------------*/

//        登陆验证

function username_change(){
//	var name = document.getElementById("username");
//	var nameP = document.getElementById("usernameP");
//	var pswd = document.getElementById("password");
//	var pswdP = document.getElementById("passwordP");
//	if (name.value!="耿耿于怀"||pswd.value!="123456") {
//		nameP.style.display="block";
//		name.style.border="1px solid red";
//		pswd.style.border="1px solid red";
//		pswdP.style.display="block";
//	}else{
//		nameP.style.display="none";
//		name.style.border="1px solid #ccc";
//		pswd.style.border="1px solid #ccc";
//		pswdP.style.display="none";
//	}
	
}



//       注册验证
//手机号码验证
function tel_change(){
	var tel = document.getElementById("tel");
	var telP = document.getElementById("telP");
	if (tel.value.length!=11) {
		telP.style.display="block";
		tel.style.border="1px solid red";
	}else{
		telP.style.display="none";
		tel.style.border="1px solid #ccc";
	}
	
}

//验证,验证码是否正确

function yanzhengma_change(){
	var yanzhengma = document.getElementById("yanzhengma");
	var yanzhengmaP = document.getElementById("yanzhengmaP");
	var yzm = document.getElementsByClassName("yzm")[0];
	if (yanzhengma.value!=yzm.innerHTML) {
		yanzhengma.style.border="1px solid red";
		yanzhengmaP.style.display="block";
	}else{
		yanzhengma.style.border="1px solid #ccc";
		yanzhengmaP.style.display="none";
	}
	
}
//验证 短信码是否为6位数
function duanxinma_change(){
	var duanxinma = document.getElementById("duanxinma");
	var duanxinmaP = document.getElementById("duanxinmaP");
	if (duanxinma.value.length!=6) {
		duanxinma.style.border="1px solid red";
		duanxinmaP.style.display="block";
	}else{
		duanxinma.style.border="1px solid #ccc";
		duanxinmaP.style.display="none";
	}
}
//验证是否含有非法词汇
function yonghuming_change(){
	var yhm = document.getElementById("yonghuming");
	var yhmP = document.getElementById("yonghumingP");
	var minggancihui=',日,干,恐怖分子,台独,你麻痹,你妈逼,草,';
	var yhmv = yhm.value;
	function  checkminganci(yhmv){
		if(minggancihui.indexOf(","+yhmv+",")>=0){
			yhm.style.border="1px solid red";
			yhmP.style.display="block";
			return;
		}else{
			yhm.style.border="1px solid #ccc";
			yhmP.style.display="none";
			return;
		}
	}
	checkminganci(yhmv);
	
	
	
}
